package com.hmo.automatic;

import android.app.Instrumentation;
import android.app.KeyguardManager;
import android.content.Context;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements Runnable {

    private static Boolean hook=false;

    public Boolean getHook() {
        return hook;
    }

    public static void setHook(Boolean hook) {
        MainActivity.hook = hook;
    }

    private static MainActivity mainActivity;

    public static MainActivity getMainActivity(){
        return mainActivity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("主界面", "onCreate: " );
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        KeyguardManager mKeyguard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);//锁屏解锁
        mKeyguard.newKeyguardLock("").disableKeyguard();
        mainActivity=this;
        //new Thread(this).start();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void run() {
        while (true){
            if (getHook()){
                Instrumentation instrumentation = new Instrumentation();
                instrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_HEADSETHOOK);
            }
            SystemClock.sleep(10000);
            Log.e("线程循环", "run: "+hook );
        }
    }

    public void hook(View view) {
        new Thread(this).start();
    }

    public void aaa(View view) {

    }
}